<template>
	<view class="tab-bar">
		<view v-for="(item, index) in tabs" :key="index" class="tab-item" :class="{ active: currentIndex === index }"
			@click="switchTab(index)">
			<text>{{ item.text }}</text>
		</view>

	</view>
</template>

<script>
	import {
		getOrder,
		sign
	} from '@/api/sign.js';
	import {
		getSign
	} from '@/api/delivery.js';
	import axios from '@/util/http'
	export default {
		data() {
			return {
				currentIndex: 1,
				tabs: [{
						text: '全部'
					},
					{
						text: '未签收'
					},
					{
						text: '已签收'
					},
					// 添加更多 Tab
				],
				items: [

				],
				type: 0,
				req: {
					contactInformation: '',
					beginTime: '',
					endTime: ''
				}
			}
		},
		props: {
			contact: {
				type: String,
				required: true
			},
			selectedOption: {
				type: String,
				required: true
			}
		},
		methods: {
			switchTab(index) {
				console.log(this.contact)
				this.currentIndex = index;
				//全部
				if (this.currentIndex == 0) {
					uni.showLoading({
									        title: '加载中'
									  })
					getOrder({
						contactInformation: this.contact
					}).then(res => {
						uni.hideLoading()
						this.items = res.data.data
						getSign({
							contactInformation: this.contact,
							type: 3
						}).then(res => {
							let newItem = res.data.data
							newItem.forEach(item => {
								this.items.push(item);
							});
							uni.hideLoading()
							this.$emit('update:data', {
								currentIndex: this.currentIndex,
								items: [...this.items]
							});
						}).catch((error) => {
							uni.hideLoading()
						});
					}).catch((error) => {
						uni.hideLoading()
					});
				}
				//未提货
				if (this.currentIndex === 1) {
					this.type = 0
					console.log(this.contact)
					const queryParams = {
						contactInformation: this.contact, // 示例参数，根据实际需求调整
						type: this.type, // 示例参数，根据实际需求调整
						// 可以添加更多参数...
					};
					uni.showLoading({
									        title: '加载中'
									  })
					sign(queryParams).then(res => {
						this.items = res.data.data
						getSign({
							contactInformation: this.contact,
							type: 0
						}).then(res => {
							uni.hideLoading()
							let newItem = res.data.data
							newItem.forEach(item => {
								this.items.push(item);
							});
							this.$emit('update:data', {
								currentIndex: this.currentIndex,
								items: [...this.items]
							});
						}).catch((error) => {
							uni.hideLoading()
						});
					}).catch((error) => {
						console.error('Error fetching appointment:', error);
						uni.hideLoading()
					});
				}
				//已提货
				if (this.currentIndex === 2) {
					this.type = 1
					const queryParams = {
						contactInformation: this.contact, // 示例参数，根据实际需求调整
						type: this.type, // 示例参数，根据实际需求调整
						// 可以添加更多参数...
					};
					uni.showLoading({
									        title: '加载中'
									  })
					sign(queryParams).then(res => {
						this.items = res.data.data
						getSign({
							contactInformation: this.contact,
							type: 1
						}).then(res => {
							uni.hideLoading()
							let newItem = res.data.data
							newItem.forEach(item => {
								this.items.push(item);
							});
							this.$emit('update:data', {
								currentIndex: this.currentIndex,
								items: [...this.items]
							});
						}).catch((error) => {
							uni.hideLoading()
						});
					}).catch((error) => {
						console.error('Error fetching appointment:', error);
						uni.hideLoading()
					});
				}
				// 触发自定义事件，并传递数据
				console.log(this.items)
			}
		},
	}
</script>

<style scoped>
	@import "signTabBar.css";
</style>